package com.zhw.mybatis;

import com.zhw.mybatis.config.DataSource;
import com.zhw.mybatis.config.ZhwConfiguration;
import com.zhw.mybatis.entity.Goods;
import com.zhw.mybatis.executor.SimpleExecutor;
import com.zhw.mybatis.executor.ZhwExecutor;
import com.zhw.mybatis.mapper.GoodsMapper;
import com.zhw.mybatis.mapper.OrdersMapper;
import com.zhw.mybatis.sqlSession.ZhwSqlSession;


public class ZhwMybatisTest {

    public static void main(String[] args) {

        DataSource dataSource = new DataSource();
        dataSource.setUrl("jdbc:mysql://192.168.99.100:3306/mybatis_test");
        dataSource.setDriver("com.mysql.jdbc.Driver");
        dataSource.setUsername("root");
        dataSource.setPassword("root");

        ZhwConfiguration config = ZhwConfiguration.SingleZhwConfiguration.INSTENCE.getInstence();
        config.setDataSource(dataSource);
        config.setScanPath("com.zhw.mybatis.xml");
        config.addMappers(OrdersMapper.class);
        config.addMappers(GoodsMapper.class);
        config.build();

        ZhwExecutor zhwExecutor = new SimpleExecutor();
        ZhwSqlSession zhwSqlSession = new ZhwSqlSession(config,zhwExecutor);//SqlSession sqlSession = sqlSessionFactory.openSession();

        GoodsMapper goodsMapper = zhwSqlSession.getMapper(GoodsMapper.class);
        Goods goods = goodsMapper.selectGoods(1);
        System.out.println(goods);

    }

}